<%@ page import="com.mapper.StoreMapper" %>
<%@ page import="com.Imp.StoreMapperImpl" %>
<%@ page import="com.entity.Store" %>
<%@ page import="com.mapper.CuisineMapper" %>
<%@ page import="com.Imp.CuisineMapperImpl" %>
<%@ page import="com.entity.Cuisine" %>
<%@ page import="java.util.List" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>FoodExpress</title>
    <!-- 新 Bootstrap5 核心 CSS 文件 -->
    <link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/5.1.1/css/bootstrap.min.css">

    <!--  popper.min.js 用于弹窗、提示、下拉菜单 -->
    <script src="https://cdn.staticfile.org/popper.js/2.9.3/umd/popper.min.js"></script>

    <!-- 最新的 Bootstrap5 核心 JavaScript 文件 -->
    <script src="https://cdn.staticfile.org/twitter-bootstrap/5.1.1/js/bootstrap.min.js"></script>
    <link rel="stylesheet" type="text/css" href="css/main.css">
</head>
<body>

<div class="container-fluid">
    <div class="row">
        <nav class="navbar navbar-expand-lg navbar-dark bg-dark">
            <div class="container-fluid">
                <a class="navbar-brand" href="main_merchant.jsp"><img src="img/caidan.png" height="35" width="35">导航</a>
                <ul class="navbar-nav ms-auto mb-2 mb-lg-0">
                    <li class="nav-item">
                        <a class="nav-link" href="login.jsp">退出登录</a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link" href="#">关于我们</a>
                    </li>
                </ul>
            </div>
        </nav>
    </div>

    <div class="row">
        <div class="col-md-2 sidebar">
            <div class="sidebar-menu">
                <ul>
                    <li class="active"><a href="main_merchant.jsp"><img src="img/main.png" height="18" width="18">&nbsp首页</a></li>
                    <!-- 折叠菜单 -->
                    <div>
                        <li data-bs-toggle="collapse" data-bs-target="#collapseMenu1" aria-expanded="false" aria-controls="collapseMenu1">
                            <a href="#" class="text-start "><img src="img/shop.png" height="18" width="18">&nbsp我的店铺</a>
                        </li>
                        <div class="collapse mt-3" id="collapseMenu1">
                            <ul class="list-group">
                                <li><a href="myStore.jsp" class="text-start small">店铺信息</a></li>
                                <li><a href="myDeliveryman.jsp" class="text-start small">送餐员详情</a></li>
                            </ul>
                        </div>
                    </div>
                    <div>
                        <li data-bs-toggle="collapse" data-bs-target="#collapseMenu2" aria-expanded="false" aria-controls="collapseMenu2">
                            <a href="#" class="text-start " style="background-color: #55aaff"><img src="img/dish.png" height="18" width="18">&nbsp菜品管理</a>
                        </li>
                        <div class="collapse mt-3" id="collapseMenu2">
                            <ul class="list-group">
                                <li><a href="myCuisines.jsp" class="text-start small" >菜品信息</a></li>
                            </ul>
                        </div>
                    </div>

                    <div>
                        <li data-bs-toggle="collapse" data-bs-target="#collapseMenu3" aria-expanded="false" aria-controls="collapseMenu3">
                            <a href="#" class="text-start "><img src="img/order.png" height="18" width="18">&nbsp订单管理</a>
                        </li>
                        <div class="collapse mt-3" id="collapseMenu3">
                            <ul class="list-group">
                                <li><a href="orderAllocation.jsp" class="text-start small">未分配</a></li>
                                <li><a href="completedOrder.jsp" class="text-start small">已完成</a></li>
                            </ul>
                        </div>
                    </div>
                    <li><a href="information_merchant.jsp"><img src="img/personal.png" height="18" width="18">&nbsp个人中心</a></li>
                </ul>
            </div>
        </div>


        <div class="col-md-10 main-content" >
            <div v-for="store in stores" :key="store.id" class="store-info">

                <div class="accordion-body">
                    <table class="table table-striped">
                        <%
                            String merchantId = (String) session.getAttribute("username");
                            //由商家账号获取到所包含的店铺号
                            StoreMapper storeMapper = new StoreMapperImpl();
                            Store store = storeMapper.getStoresBymerchantId(merchantId);
                            session.setAttribute("storeId",store.getStoreId());
                            if(store != null){
                        %>
                        <thead>
                        <tr>
                            <th>序号</th>
                            <th>菜品名称</th>
                            <th>菜品图片</th>
                            <th>原料</th>
                            <th>单价</th>
                            <th>操作    <button type="button" class="btn btn-primary float-end" data-bs-toggle="modal" data-bs-target="#myModal">
                                添加菜品
                            </button></th>
                        </tr>
                        </thead>
                        <%
                            //由店铺号找到店铺下的菜品
                            CuisineMapper cuisineMapper = new CuisineMapperImpl();
                            List<Cuisine> cuisineList = cuisineMapper.getCuisinesByStoreId(store.getStoreId());
                            if(cuisineList != null){
                                for(Cuisine cuisine : cuisineList) {
                        %>
                        <tbody>
                        <tr>
                            <td><%=cuisine.getCuisineId()%></td>
                            <td>
                                <%=cuisine.getCuisineName()%>
                            </td>
                            <td><img src=<%=cuisine.getPhotoURL()%> class="rounded" alt="Cinque Terre" width="130" height="100">  </td>
                            <td><%=cuisine.getMaterials()%></td>
                            <td>￥<%=cuisine.getPrice()%></td>
                            <td>
                                <form action="CuisineController?op=delete" method="post">
                                    <input type="hidden" name="cuisineId" value="<%=cuisine.getCuisineId()%>">
                                    <button type="submit" class="btn btn-danger btn-sm">删除</button>
                                </form>
                            </td>
                        </tr>
                        </tbody>
                        <%
                            }}else{
                        %>
                        <h1>  您的店铺下尚未添加菜品哟，请您快快添加！</h1>
                        <%
                            }}else{
                        %>
                        <h1>  您暂且没有商店哟，请您快快添加！</h1>
                        <%
                            }
                        %>
                    </table>

                </div>

                <!-- 模态框 -->
                <div class="modal" id="myModal">
                    <div class="modal-dialog">
                        <div class="modal-content">
                            <!-- 模态框头部 -->
                            <div class="modal-header">
                                <h4 class="modal-title">添加新菜品</h4>
                                <button type="button" class="btn-close" data-bs-dismiss="modal"></button>
                            </div>
                            <!-- 模态框内容 -->
                            <div class="modal-body">
                                <form action="CuisineController?op=add" method="post" enctype="multipart/form-data">
                                    <div class="input-group mb-4">
                                        <span class="mt-2">菜品名称：</span>
                                        <input type="text" class="form-control" name="name" placeholder="请输入菜品名称">
                                    </div>
                                    <div class="input-group mb-4">
                                        <span class="mt-2">菜品序号：</span>
                                        <input type="text" class="form-control" name="cuisineId" placeholder="请输入菜品序号">
                                    </div>
                                    <div class="input-group mb-4">
                                        <span class="mt-2">上传图片：</span>
                                        <input type="file" name="imageFile">
                                    </div>
                                    <div class="input-group mb-4">
                                        <span class="mt-2">原料：</span>
                                        <input type="text" class="form-control" name="materials" placeholder="请输入菜品原料">
                                    </div>
                                    <div class="input-group mb-4">
                                        <span class="mt-2">单价：</span>
                                        <input type="text" class="form-control" name="price" placeholder="请输入单价">
                                    </div>
                                    <div class="modal-footer">
                                        <button type="submit" class="btn btn-success" data-bs-dismiss="modal">提交</button>
                                        <button type="button" class="btn btn-danger" data-bs-dismiss="modal">关闭</button>
                                    </div>
                                </form>
                            </div>
                        </div>
                    </div>
                </div>


            </div>
        </div>
    </div>
</div>
<script>
    function chooseFile() {
        document.getElementById('fileInput').click();
    }
    function displaySelectedFileName(event) {
        const fileInput = event.target;
        const selectedFile = fileInput.files[0];
        const fileNameDisplay = document.getElementById('selectedFileName');
        fileNameDisplay.textContent = selectedFile ? selectedFile.name : '';
    }
</script>
</body>
</html>

